<?php
header("Content-Type: text/html");
header("charset: utf-8");
include_once("_common.php");

if(urldecode($SIDO) == "서울"){
$areaStr =  " SELECT SIDO, GUGUN, (select count(1) from ".$table_name." b where instr(b.wr_area,a.SIDO) > 0 and instr(b.wr_area,a.GUGUN) > 0) totcnt   ";
$areaStr .= " FROM g4_area a    ";
$areaStr .= " WHERE SIDO = '".urldecode($SIDO)."'     ";
$areaStr .= " GROUP BY SIDO, GUGUN  ";
$areaStr .= " ORDER BY GUGUN";
$mapResult = sql_query($areaStr);



echo "	<td class=\"left22\">";
echo "		<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "			<tr>";
echo " 				<td class=\"txt12_g\">";
echo "					<input type=\"checkbox\" name=\"seoul_all\" id=\"seoul_all\" value=\"서울\" onclick=\"javascript:allCheckYn('seoul');\" />서울 전지역";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td height=\"15\"><img src=\"../img/product/dot.gif\" width=\"242\" height=\"1\" /></td>";
echo "			</tr>";
echo "		</table>";
echo "		<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "			<tr>";
echo "				<td colspan=\"3\" class=\"txt12_g1\">강남지역</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|강남\"  onclick=\"javascript:attrCheckYn('seoul');\" />강남";

						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "강남")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|관악\"  onclick=\"javascript:attrCheckYn('seoul');\" />관악";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "관악")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|강서\"  onclick=\"javascript:attrCheckYn('seoul');\" />강서";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "강서")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "					</tr>";
echo "					<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|서초\"  onclick=\"javascript:attrCheckYn('seoul');\" />서초";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "서초")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|동작\"  onclick=\"javascript:attrCheckYn('seoul');\" />동작";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "동작")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|양천\"  onclick=\"javascript:attrCheckYn('seoul');\" />양천";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "양천")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|송파\"  onclick=\"javascript:attrCheckYn('seoul');\" />송파";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "송파")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|영등포\"  onclick=\"javascript:attrCheckYn('seoul');\" />영등포";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "영등포")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|구로\"  onclick=\"javascript:attrCheckYn('seoul');\" />구로";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "구로")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|강동\"  onclick=\"javascript:attrCheckYn('seoul');\" />강동";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "강동")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|금천\"  onclick=\"javascript:attrCheckYn('seoul');\" />금천";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "금천")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					&nbsp;";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td colspan=\"3\" class=\"txt12_g1\">&nbsp;</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td colspan=\"3\" class=\"txt12_g1\">강북지역</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|광진\"  onclick=\"javascript:attrCheckYn('seoul');\" />광진";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "광진")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|노원\"  onclick=\"javascript:attrCheckYn('seoul');\" />노원";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "노원")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|마포\"  onclick=\"javascript:attrCheckYn('seoul');\" />마포";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "마포")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|성동\"  onclick=\"javascript:attrCheckYn('seoul');\" />성동";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "성동")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|성북\"  onclick=\"javascript:attrCheckYn('seoul');\" />성북";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "성북")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|서대문\"  onclick=\"javascript:attrCheckYn('seoul');\" />서대문";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "서대문")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|동대문\"  onclick=\"javascript:attrCheckYn('seoul');\" />동대문";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "동대문")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|강북\"  onclick=\"javascript:attrCheckYn('seoul');\" />강북";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "강북")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|은평\"  onclick=\"javascript:attrCheckYn('seoul');\" />은평";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "은평")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|중랑\"  onclick=\"javascript:attrCheckYn('seoul');\" />중랑";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "중랑")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|도봉\"  onclick=\"javascript:attrCheckYn('seoul');\" />도봉";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "도봉")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|종로\"  onclick=\"javascript:attrCheckYn('seoul');\" />종로";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "종로")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|중구\"  onclick=\"javascript:attrCheckYn('seoul');\" />중구";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "중구")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "					<strong>";
echo "						<input type=\"checkbox\" name=\"seoul_attr\" id=\"seoul_attr\" value=\"서울|용산\"  onclick=\"javascript:attrCheckYn('seoul');\" />용산";
						@mysql_data_seek($mapResult,0);
						for ($i=0; $row=sql_fetch_array($mapResult); $i++) {
							if (strstr($row['GUGUN'], "용산")){
								echo "(".$row['totcnt'].")";
								break;
							}
						}
echo "					</strong>";
echo "				</td>";
echo "				<td width=\"33%\">";
echo "				</td>";
echo "			</tr>";
echo "			<tr>";
echo "				<td colspan=\"3\">&nbsp;</td>";
echo "			</tr>";
echo "		</table>";
echo "		</td>";
	
}else{
$areaStr =  " SELECT SIDO, GUGUN, (select count(1) from ".$table_name." b where instr(b.wr_area,a.SIDO) > 0 and instr(b.wr_area,a.GUGUN) > 0) totcnt   ";
$areaStr .= " FROM g4_area a    ";
$areaStr .= " WHERE SIDO = '".urldecode($SIDO)."'     ";
$areaStr .= " GROUP BY SIDO, GUGUN  ";
$areaStr .= " ORDER BY GUGUN";
$mapResult = sql_query($areaStr);

echo "<td class=\"left22\">";
echo "  <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
echo "    <tr>";
echo "      <td class=\"txt12_g\">";
echo "        <input type=\"checkbox\" name=\"".$SIDO_ENG."_all\" id=\"".$SIDO_ENG."_all\" value=\"".urldecode($SIDO)."\" onclick=\"javascript:allCheckYn('".$SIDO_ENG."');\" />".urldecode($SIDO)." 전지역";
echo "      </td>";
echo "    </tr>";
echo "    <tr>";
echo "      <td height=\"15\"><img src=\"../img/product/dot.gif\" width=\"242\" height=\"1\" /></td>";
echo "    </tr>";
echo "  </table>";
echo "  <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
          
for ($i=0; $row=sql_fetch_array($mapResult); $i++){
	
	if($i == 0 || $i % 3 == 0){
    	echo "    <tr>";
	}
	echo "       <td width=\"33%\">";
	echo "         <strong>";
	echo "           <input type=\"checkbox\" name=\"".$SIDO_ENG."_attr\" id=\"".$SIDO_ENG."_attr\" value=\"".urldecode($SIDO)."|".$row['GUGUN']."\" onclick=\"javascript:attrCheckYn('".$SIDO_ENG."');\" />".str_replace(" ", "<br>&nbsp;&nbsp;&nbsp;&nbsp;", $row['GUGUN'])."({$row['totcnt']})";
	echo "         </strong>";
	echo "       </td>";
	if($i % 3 == 2){
		echo "    </tr>";
	}
	
	if($i == mysql_num_rows($mapResult)-1){
		if($i % 3 == 1){
			echo "       <td width=\"33%\">&nbsp;";
			echo "       </td>";
		}else if($i % 3 == 0){
			echo "       <td width=\"33%\">&nbsp;";
			echo "       </td>";
			echo "       <td width=\"33%\">&nbsp;";
			echo "       </td>";
		}
		echo "    </tr>";
	}
}

echo "          <tr>";
echo "            <td colspan=\"3\">&nbsp;</td>";
echo "          </tr>";
echo "        </table>";
echo "      </td>";
}                

?>